﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TuxedoLib;

namespace SpaceSquirrel
{
	public static class ImageLibrary
	{
		private static Dictionary<string, Image> images = new Dictionary<string, Image>();
		private static Dictionary<string, Image> reverseImages = new Dictionary<string, Image>();

		public static Image GetImage(string path)
		{
			Image output;
			if (!images.TryGetValue(path, out output))
			{
				output = AssetLoader
					.LoadFromProject("images/" + path, typeof(ImageLibrary).Assembly, false)
					.ConvertDataToImage();

				Image bg = new Image(output.Width, output.Height);
				bg.Fill(255, 0, 255);
				bg.Blit(output, 0, 0);
				bg.SetColorKey(255, 0, 255, 255);

				images[path] = bg;
			}
			return output;
		}

		public static Image GetBackwardsImage(string path)
		{
			Image output;
			if (!reverseImages.TryGetValue(path, out output))
			{
				output = GetImage(path);
				output = TuxedoLib.Transform.FlipHorizontal(output);
				reverseImages[path] = output;
			}
			return output;
		}
	}
}
